<template>
  <div>
    <div class="herdertop">
      <img src="../../assets/top.png" alt="" class="topImg" />
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>活动统计</el-breadcrumb-item>
        <el-breadcrumb-item>优惠券使用数据</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="center" style="padding-top: 0px;">
      <div class="hander">优惠券使用数据</div>
      <div class="orderList">
        <div class="entirety">
          <div>
            <div class="search">
              <!--  账号状态搜索信息 -->

              <div class="demo-input-suffix">
                活动名称

                <el-select
                  style="width: 65%"
                  @change="onChange"
                  v-model="activityNo"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in ChannelList"
                    :key="item.activityNo"
                    :label="item.activityName"
                    :value="item.activityNo"
                  >
                  </el-option>
                </el-select>
              </div>

              <div class="demo-input-suffix">
                渠道

                <el-select
                  style="width: 55%"
                  v-model="channelCode"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in ActivityChannelList[0]"
                    :key="item.channelCode"
                    :label="item.channelName"
                    :value="item.channelCode"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="demo-input-suffix">
                是否新用户

                <el-select
                  style="width: 55%"
                  v-model="userGenre"
                  placeholder="请选择"
                >
                  <el-option label="全部用户" value="0"></el-option>
                  <el-option label="新用户" value="1"></el-option>
                  <el-option label="老用户" value="2"></el-option>
                </el-select>
              </div>
              <!--  账号状态搜索信息 -->
              <div class="demo-input-suffix">
                <el-button
                  style="background-color:#fd804c;color: #fff;"
                  :disabled="total == 0 ? true : false"
                  @click="downloadNew"
                  >导出</el-button
                >
              </div>
              <div class="demo-input-suffix">
                <el-button
                  style="background-color:#fd804c;color: #fff;"
                  @click.native.prevent="isSelect"
                  >查询</el-button
                >
              </div>
              <div class="demo-input-suffix">
                <el-button type="warning" @click.native.prevent="isEmpty"
                  >清空</el-button
                >
              </div>
            </div>
            <div class="top">
              <div class="demo-input-suffix">
                注册时间
                <el-date-picker
                  v-model="TimeLIst"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  size="mini"
                  align="right"
                  prefix-icon="el-icon-date"
                  clear-icon="el-icon-close"
                  :editable="false"
                >
                </el-date-picker>
              </div>
            </div>
          </div>
        </div>

        <!--  员工列表栏位-->
        <div class="entirety">
          <div class="footer">
            <el-table :data="tableData" style="width: 100%">
              <el-table-column prop="userName" label="用户名称">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.userName }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="userPhoneNo" label="用户手机号">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.userPhoneNo }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="activityName" label="活动名称">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.activityName }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="activityNo" label="活动ID">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.activityNo }}
                  </div>
                </template>
              </el-table-column>

              <el-table-column prop="channelName" label="来源渠道">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.channelName }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="channelCode" label="渠道ID">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.channelCode }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="couponStatus" label="优惠券状态">
                <template slot-scope="scope">
                  <div>
                    {{
                      scope.row.couponStatus == "2"
                        ? "已过期"
                        : scope.row.couponStatus == "1"
                        ? "已使用"
                        : scope.row.couponStatus == "0"
                        ? "未使用"
                        : ""
                    }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="receiveTime" label="优惠券领取时间">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.receiveTime }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="couponTitle" label="优惠券名称">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.couponTitle }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="goodsTitle" label="优惠券购买商品名称">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.goodsTitle }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="totalAmount" label="订单金额">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.totalAmount }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="totalDiscountAmount" label="优惠金额">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.totalDiscountAmount }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="paymentAmount" label="支付金额">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.paymentAmount }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="orderNo" label="对应订单号">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.orderNo }}
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="block">
              <div class="left"></div>
              <div class="right">
                <el-pagination
                  layout="total, sizes, prev, pager, next, jumper"
                  class="page"
                  @size-change="sizeChangeHandle"
                  @current-change="currentChangeHandle"
                  :current-page="pageIndex"
                  :page-size="pageSize"
                  :total="total"
                >
                </el-pagination>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";

export default {
  data() {
    return {
      channelCode: "",
      TimeLIst: [new Date() - 3600 * 24 * 30 * 1000, new Date()],
      pageIndex: 1,
      pageSize: 20,
      total: 0,
      tableData: [],
      ActivityChannelList: [],
      userNewAmount: 0,
      userVolume: 0,
      palceTransition: 0,
      userNewPlaceAmount: 0,
      userOldPlaceAmount: 0,
      ChannelList: [],
      business: [],
      activityNo: "",
      channelCode: "",
      newUseCoupon: 0,
      oldUseCoupon: 0,
      timeEnd: "",
      timeStart: "",
      userGenre: "0"
    };
  },
  activated() {
    (this.activityNo = ""), (this.channelCode = ""), this.selectChannelList();
    this.selectActivityChannelList();
  },

  methods: {
    isSelect() {
      (this.pageIndex = 1), (this.pageSize = 20), this.DetailByPage();
    },
    //导出
    downloadNew() {
      const timeStart =
        moment(this.TimeLIst[0]).format("YYYY-MM-DD HH:mm:ss") || "";
      const timeEnd =
        moment(this.TimeLIst[1]).format("YYYY-MM-DD HH:mm:ss") || "";
      let num = this.total == 0 ? 10 : this.total;

      if (window.location.host == "hs.xstarlife.com") {
        window.location.href = `https://hs.xstarlife.com/api/activityadmin/statistic/downloadActivityUserCouponCondition?page=${this.pageIndex}&size=${num}&timeStart=${timeStart}&timeEnd=${timeEnd}&userGenre=${this.userGenre}&oldUseCoupon=${this.oldUseCoupon}&newUseCoupon=${this.newUseCoupon}&channelCode=${this.channelCode}&activityNo=${this.activityNo}`;
      } else {
        window.location.href = `https://m.goltestarlife.com/activityadmin/statistic/downloadActivityUserCouponCondition?page=${this.pageIndex}&size=${num}&timeEnd=${timeEnd}&timeStart=${timeStart}&userGenre=${this.userGenre}&oldUseCoupon=${this.oldUseCoupon}&newUseCoupon=${this.newUseCoupon}&channelCode=${this.channelCode}&activityNo=${this.activityNo}`;
      }
    },
    isEmpty() {
      (this.channelCode = ""),
        (this.TimeLIst = [new Date() - 3600 * 24 * 30 * 1000, new Date()]),
        (this.pageIndex = 1),
        (this.pageSize = 20),
        (this.total = 0),
        (this.tableData = []),
        (this.ActivityChannelList = []),
        (this.userNewAmount = 0),
        (this.userVolume = 0),
        (this.palceTransition = 0),
        (this.userNewPlaceAmount = 0),
        (this.userOldPlaceAmount = 0),
        (this.ChannelList = []),
        (this.business = []),
        (this.channelCode = ""),
        (this.newUseCoupon = "0"),
        (this.oldUseCoupon = "0"),
        (this.timeEnd = ""),
        (this.timeStart = ""),
        (this.userGenre = "0");
      this.selectChannelList();
    },
    //查询活动枚举
    selectChannelList() {
      this.$http({
        url: `/activityadmin/statistic/selectChannelList`,
        method: "GET"
      }).then(res => {
        this.ChannelList = res.data;
        this.activityNo = res.data && res.data[0].activityNo;
        this.DetailByPage();
        this.selectActivityChannelList(this.activityNo);
      });
    },
    onChange() {
      this.selectActivityChannelList(this.activityNo);
      this.ActivityChannelList = [];
      this.channelCode = "";
    },
    //查询所有活动对应渠道
    selectActivityChannelList(activityNo) {
      this.$http({
        url: `/activityadmin/statistic/selectActivityChannelList`,
        method: "GET"
      }).then(res => {
        console.log("this.activityNo,,,,", activityNo);
        console.log(",查询所有活动对应渠道", res);
        let dataList = [];
        let ActivityChannelList = [];
        dataList = res.data.filter(item => item.activityNo == activityNo);
        dataList.length > 0 &&
          dataList.map(item => ActivityChannelList.push(item.channelEnumList));
        this.ActivityChannelList = ActivityChannelList;
      });
    },

    //活动用户优惠券使用情况统计
    DetailByPage() {
      this.$http({
        url: `/activityadmin/statistic/selectActivityUserCouponCondition`,
        method: "POST",
        data: {
          activityNo: this.activityNo,
          channelCode: this.channelCode,
          newUseCoupon: this.newUseCoupon,
          oldUseCoupon: this.oldUseCoupon,
          userGenre: Number(this.userGenre),
          timeStart:
            this.TimeLIst && this.TimeLIst[0]
              ? moment(this.TimeLIst && this.TimeLIst[0]).format(
                  "YYYY-MM-DD HH:mm:ss"
                )
              : "",
          timeEnd:
            this.TimeLIst && this.TimeLIst[1]
              ? moment(this.TimeLIst && this.TimeLIst[1]).format(
                  "YYYY-MM-DD HH:mm:ss"
                )
              : "",
          size: this.pageSize,
          page: this.pageIndex
        }
      }).then(res => {
        this.tableData = res;
        if (res.length == 0) {
          this.total = 0;
        } else {
          this.total = parseInt(res[0].listSize);
        }
      });
    },

    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;

      this.DetailByPage();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;

      this.DetailByPage();
    }
  }
};
</script>
<style scoped lang="scss">
.block {
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 10px 0 10px;
}
.left {
  font-size: 15px;
}
.hander {
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  font-weight: 900;
}
.balance-searchMoney {
  display: flex;
  align-items: center;
}
.input {
  flex: 1;
  margin-left: 5px;
}
.nav {
  width: 102%;
  margin-top: 12px;
  margin-left: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.money {
  // height: 100px;
  background-color: #fff;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  border-radius: 6px;
  // margin-bottom: 24px !important;
}
.money div {
  color: #333;
  box-sizing: border-box;
}
.one {
  font-size: 20px;
  font-weight: 500;
  color: #000;
}
.money .two {
  font-size: 12px;
  color: #666;
  font-weight: 500;
}
.moneyRight {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
}
.moneyImg {
  width: 72px;
  height: 72px;
}
.f16 {
  font-size: 16px;
}
.moneyLeft {
  flex: 1;
  background: #f2f2f2;
  text-align: center;
  padding-top: 10px;
  padding-bottom: 10px;
}
.news {
  margin-left: 60%;
}
.orderList {
  background-color: #ebeef1;
  padding-right: 40px;
  padding-top: 1px;
  padding-bottom: 1px;
  display: block;
  font-size: 16px;
  border-radius: 20px;
  list-style-type: none;
}
.entirety {
  width: 100%;
  margin: 10px;
  height: 100%;
  padding: 10px;
  background-color: #fff;
  border-radius: 10px;
  display: flex;
  padding-left: 10px;
  .basic {
    font-size: 18px;
    font-weight: 900;
    margin-top: 2%;
    margin-bottom: 1%;
    margin-left: 1%;
  }
}
.footer {
  width: 100%;
  display: flex;
  overflow: hidden;
  flex-direction: column;
}
.page {
  margin-top: 15px;
}
.search {
  margin-bottom: 15px;
}
.top {
  display: flex;
  justify-content: space-between;
}
/deep/ .el-range-editor--mini {
  height: 35px;
  width: 350px;
  text-align: center;
}
/deep/ .el-range-separator {
  line-height: 25px;
}
.overall {
  width: 100%;
  height: auto;
  display: flex;

  justify-content: space-between;
  margin-top: 3%;
  .left {
    width: 20%;
    height: auto;
  }
  .right {
    width: 80%;
    height: auto;
  }
}
.demo-input-suffix {
  margin-left: 2%;
}
.select {
  width: 65%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}
.herdertop {
  height: 8vh;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
.topImg {
  margin-right: 20px;
}
/deep/ .itemClass .el-form-item__content {
  width: 350px;
}
.userSearch {
  display: flex;
  /deep/ .el-input__inner {
    box-sizing: border-box;
    height: 40px;
    border-radius: 0;
    width: 132px;
    border: 1px solid #dcdfe6;
  }
  /deep/ .el-icon-arrow-up:before {
    position: relative;
    top: -4px;
  }
  /deep/ .el-button {
    height: 40px;
    border-radius: 0;
    background-color: #fff;
    border: 1px solid #dcdfe6;
    border-left: none;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    position: relative;
    .el-icon-search {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-right: none;
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }
}
.selects {
  width: 55%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}
/deep/ .but {
  background: #fd7097;
  color: #fff;
  margin-bottom: 1%;
}
</style>
